package map;

import java.util.HashSet;

public class L202 {
    public boolean isHappy(int n) {
        HashSet<Integer> hash = new HashSet<>();
        while (n!=1){
            int sumofsqu = sumofsqu(n);
            if (hash.contains(sumofsqu)){
                return false;
            }else {
                hash.add(sumofsqu);
            }
            n=sumofsqu;
        }
        return true;
    }

    public static  int sumofsqu(int number){

        int sum=0;
        while (number>0){
            int m=number%10;
            sum+=m*m;
            number/=10;
        }
        return sum;
    }

    public static void main(String[] args) {
        int n=19;
        L202 l202 = new L202();
        boolean happy = l202.isHappy(n);
        System.out.println(happy);
    }

}
